package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.activity.ActivityListDTO;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author diva
 * @date 2025/10/9 14:52
 * @ProjectName
 */

@RestController
@RequestMapping("/activities")
@Slf4j
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    @GetMapping
    public Result list(ActivityListDTO dto) {
        PageResult<Activity> pageResult = activityService.list(dto);
        return Result.success(pageResult);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        activityService.delete(id);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Activity activity){
        log.info("添加活动：{}",activity);
        activityService.add(activity);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getActivityById(@PathVariable Integer id) {
        Activity activity = activityService.getActivityById(id);
        return Result.success(activity);
    }
    @PutMapping
    public Result update( @RequestBody Activity activity) {
        log.info("修改活动：{}",activity);
        activity.setUpdateTime(LocalDateTime.now());
        activityService.update(activity);
        return Result.success();
    }
    @GetMapping("/type/{type}")
    public Result getActivityByType(@PathVariable Integer type) {
        List<Activity> list = activityService.getActivityByType(type);
        return Result.success(list);
    }


}
